package Testinterface;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-09-14
 * Time: 20:01
 */
interface USB {
    public final static int a = 10;

    public abstract void openDevise();
    public abstract void closeDevise();
}

class Mouse implements USB {
    public void openDevise() {
        System.out.println("打开鼠标");
    }
    public void closeDevise() {
        System.out.println("关闭鼠标");
    }
    public void click() {
        System.out.println("点击鼠标");
    }
}

class KeyBoard implements USB {
    public void openDevise() {
        System.out.println("打开键盘");
    }
    public void closeDevise() {
        System.out.println("关闭键盘");
    }
    public void inPut() {
        System.out.println("敲键盘");
    }
}

class Computer {
    public void poweOn() {
        System.out.println("打开电脑");
    }
    public void powerOff() {
        System.out.println("关闭电脑");
    }

    public void useComputer(USB usb) {
        poweOn();
        usb.openDevise();
        if(usb instanceof Mouse) {
            Mouse mouse = (Mouse) usb;
            mouse.click();
            //((Mouse)usb).click();

        } else if(usb instanceof KeyBoard) {
            KeyBoard keyboard = (KeyBoard) usb;
            keyboard.inPut();
            //((KeyBoard)usb).inPut();

        }
        usb.closeDevise();
        powerOff();
    }

}

public class Test1 {

    public static void main(String[] args) {
        USB usbMouse = new Mouse();
        USB usbKeyBoard = new KeyBoard();
        Computer computer1 = new Computer();



        computer1.useComputer(usbMouse);
        System.out.println("=======================");
        computer1.useComputer(usbKeyBoard);


    }


}
